package com.environment;


import com.environment.Percept;
import com.knowledge.facts.Fact;

/**
 * Represents an order to be issued.
 */
public class Order implements Comparable {
    private final int row;
    
    private final int col;
    
    private final Aim direction;
    
    /**
     * Creates new {@link Order} object.
     * 
     * @param tile map tile with my ant
     * @param direction direction in which to move my ant
     */
    public Order(Tile tile, Aim direction) {
        row = tile.getRow();
        col = tile.getCol();
        this.direction = direction;
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "o " + row + " " + col + " " + direction.getSymbol();
    }

    public Tile toDestinationTile() {
        return Percept.getInstance().getTile(new Tile(row,col), direction);
    }

    public Tile getLocation() {
        return new Tile(row,col);
    }

    @Override
    public boolean equals(Object t) {
        Order other = (Order)t;
        
        if ((toDestinationTile().getCol() == other.toDestinationTile().getCol()) &&
                (toDestinationTile().getRow() == other.toDestinationTile().getRow())) return true;        
        
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + toDestinationTile().getRow();
        hash = 97 * hash + toDestinationTile().getCol();
        return hash;
    }
    
    @Override
    public int compareTo(Object t) {
        Order other = (Order)t;
        

        if ((toDestinationTile().getCol() < other.toDestinationTile().getCol())) return -1;
        if ((toDestinationTile().getCol() > other.toDestinationTile().getCol())) return 1;
        if ((toDestinationTile().getRow() < other.toDestinationTile().getRow())) return -1;
        if ((toDestinationTile().getRow() > other.toDestinationTile().getRow())) return 1;
        
        return 0;
    }
    
}
